package org.raymond.iworks.study.mq.rabbitmq.stream.official;

import com.rabbitmq.stream.Environment;
import com.rabbitmq.stream.Producer;

/**
 * @author raymond
 * @version V1.0
 * @Description: TODO
 */
public class SuperStreamProducer {
    public static void main(String[] args) throws InterruptedException {
        try (Environment environment =
                     Environment.builder()
                             .maxConsumersByConnection(1)
                             .maxTrackingConsumersByConnection(1)
                             .build()) {

            String superStream = "invoices";

            System.out.println("Starting producer");

            Producer producer =
                    environment.producerBuilder().superStream(superStream)
                            .routing(msg -> msg.getProperties().getMessageIdAsString())
                            .producerBuilder()
                            .build();

            long idSequence = 0;
            while (true) {
                producer.send(
                        producer.messageBuilder().properties().messageId(idSequence++).messageBuilder().build(),
                        confirmationStatus -> {});
                Thread.sleep(1000);
            }
        }
    }
}
